<?php
namespace Phone\Controller;
use Think\Controller;
/**
* 
*/
class ListController extends CommonController{
	//查询快递
	public function index(){
		!$_POST['p'] && $_POST['p']=1;
		I('get.phone') && ($where["right(phone,5)"] = array('like','%'.I('get.phone').'%'));
		$_GET['no'] && $where['no']=array("LIKE","%{$_GET['no']}%");
		$where['status']=1;
		$where['user_id'] = session('id');
		$res=D("Take")->relation(true)->where($where)->page($_POST['p'].',5')->select();
		$this->assign("list",json_encode($res));
		IS_POST?$this->success($res):$this->display();
	}
	public function save(){
		!is_numeric(I("post.id")) && $this->error("参数错误,请重新查询");
		$take_time=date("Y-m-d h:i:s");
		if(D("Take")->where(array("id"=>I("post.id")))->save(array("status"=>"2","take_time"=>$take_time))){
			$info = M('Take')->where(array('id'=>(int)I('post.id')))->find();
			M('Container')->where(array('id'=>$info['container_id']))->setDec('used');
			$url = C('DOMAIN').'/Api/ApiList/updateSet?id='.$info['id']."&since=".$info['since'];
			file_get_contents($url);			
			$this->success("领取成功");
		}else{
			$this->error("参数错误,请重新查询");
		}
	}
}